package com.chookss.home.rank;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chookss.R;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.home.document.DocumentDetailActivity;
import com.chookss.home.entity.NavigationEntity;
import com.chookss.tools.Utils;
import com.chookss.view.BottomListsDialog;
import com.chookss.view.Rank2Dialog;
import com.chookss.view.RankLinkDialog;
import com.chookss.view.SelectDialogListener;
import com.chookss.wxapi.ShareActivity;

import java.util.ArrayList;
import java.util.List;

public class RankLinkAdapter extends BaseQuickAdapter<RankLinkEntity, BaseViewHolderEx> {
    private Context mContext;
    private ArrayList<NavigationEntity> data;
    private BottomListsDialog bottomListsDialog = null;
    private List<String> dialogList = new ArrayList<>();
    public RankLinkAdapter(int layoutResId, Context context, @io.reactivex.annotations.Nullable ArrayList<RankLinkEntity> data) {
        super(layoutResId, data);
        this.mContext = context;
        dialogList.add("分享");
        dialogList.add("取消");
    }

    @Override
    protected void convert(BaseViewHolderEx helper, RankLinkEntity entity) {
        LinearLayout llBg = helper.getView(R.id.llBg);
        TextView tv1 = helper.getView(R.id.tv1);
        TextView tv2 = helper.getView(R.id.tv2);
        TextView tv3 = helper.getView(R.id.tv3);
        TextView tv4 = helper.getView(R.id.tv4);
        TextView tv5 = helper.getView(R.id.tv5);
        if(helper.getItemPosition()%2==0){
            llBg.setBackgroundColor(Color.parseColor("#ffffff"));
        }else{
            llBg.setBackgroundColor(Color.parseColor("#f7f7f7"));
        }
        tv1.setText((helper.getItemPosition()+1)+"");
        tv2.setText(entity.getResourceName());
        tv3.setText(entity.getViewNum());
        tv4.setText(entity.getTsNum());
        tv5.setText(Utils.getAccurateDate(entity.getCreateTime()));
        helper.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new RankLinkDialog(mContext,entity).show();
            }
        });
        helper.getItemView().setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                bottomListsDialog = new BottomListsDialog(mContext, dialogList, new SelectDialogListener() {
                    @Override
                    public void onCancel() {

                    }

                    @Override
                    public void onListItemClick(int position, List<String> list) {
                        if (position == 0) {
                           Intent intent=new Intent(mContext, ShareActivity.class);
                           intent.putExtra("sourceType",1);
                           intent.putExtra("rankLinkData",entity);
                           mContext.startActivity(intent);
                        }
                        bottomListsDialog.dismiss();
                    }
                });
                bottomListsDialog.show();
                return true;
            }
        });
    }
}